﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZBJF.Warranty.Common.Common;
using ZBJF.Warranty.Common.Enums.System;
using ZBJF.Warranty.Model;
using ZBJF.Warranty.Model.ViewModel.InsuranceWarranty;

namespace ZBJF.Warranty.BLL
{
    public partial class InsuranceWarrantyRecordFreeService
    {
        public bool DeleteBy(long iwrID, List<long> notDeleteIWRFreeIds, string opreatUser, string userDisPlayName)
        {
            var expressionWhere = PredicateExtensions.True<InsuranceWarrantyRecordFree>();
            expressionWhere = expressionWhere.And(o => o.InsuranceWarrantyRecordId == iwrID);
            expressionWhere = expressionWhere.And(o => !notDeleteIWRFreeIds.Contains(o.ID));
            var toBeDelList = LoadEntities(expressionWhere).ToList();
            var result = false;
            toBeDelList.ForEach(o =>
            {
                #region 先记录日志
                var opreateLogs = new OpreateLogs
                {
                    CreatedTime = DateTime.Now,
                    LogTableName = "InsuranceWarrantyRecord",
                    LogSubject = "案件处理信息-删除",
                    LogTablePKID = iwrID,
                    OpreateUserAccount = opreatUser,
                    OpreateUserName = userDisPlayName
                };
                ServiceFactory.OpreateLogsServiceInstance.AddOpreateLogs(opreateLogs, string.Empty, o, OpreateType.Delete);
                #endregion
                result = DeleteEntities(o);
            });
            return result;
        }

    }
}
